package edu.pku.taas.hyperic.monitor;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class MonitorServerConfigureManager {
	private static final String PRO_HOME = "user.home";
	
	
	private static class ConfigureHelper {
		static Properties props = new Properties();
		static String filePath = System.getProperty(PRO_HOME)+ "/" + "monitor_server.conf";
		static {
			try {
				//getProps().load(HQApiHelper.class.getResourceAsStream("monitor_server.conf"));
				getProps().load(new BufferedInputStream(new FileInputStream(filePath)));
				
				System.out.println(getProps());
			} catch (IOException e) {
				e.printStackTrace();
				throw new RuntimeException(e.getMessage());
			}
		}
	}

	public static Properties getProps() {
		return ConfigureHelper.props;
	}


	public static String getStringConfigure(String key) {
		return (String) getProps().get(key);
	}

	public static int getIntConfigure(String key) {
		return Integer.parseInt((String) getProps().get(key));
	}

	public static long getLongConfigure(String key) {
		return Long.parseLong((String) getProps().get(key));
	}

	public static boolean getBooleanConfigure(String key) {
		return Boolean.parseBoolean((String) getProps().get(key));
	}

	public static float getFloatConfigure(String key) {
		return Float.parseFloat((String) getProps().get(key));
	}

	public static double getDoubleConfigure(String key) {
		return Double.parseDouble((String) getProps().get(key));
	}
	
	public static List<Map.Entry<String,String>> getConfigureList(){
		List cl = new ArrayList();
		//Entry<String,String>
		cl.addAll( getProps().entrySet());
		return cl;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		MonitorServerConfigureManager mh = new MonitorServerConfigureManager();
		long th = mh.getLongConfigure(MonitorConstants.RESOURCE_MONITOR_RESPONSE_OVERTIME_THRESHOLD);
		System.out.println(th);

	}

}
